# -*- coding: utf-8 -*-

import sys
import os
import time

# Add the src directory to sys.path for imports
sys.path.insert(0, os.path.abspath('../src'))

try:
    import sphinx_rtd_theme
except ImportError:
    sphinx_rtd_theme = None

try:
    from sphinxcontrib import spelling
except ImportError:
    spelling = None

# Check if we are building on readthedocs
RTD_BUILD = os.environ.get('READTHEDOCS', None) == 'True'

from crossbar import __version__

# -- Project information -----------------------------------------------------

project = 'Crossbar.io Application Router'
this_year = u'{0}'.format(time.strftime('%Y'))
copyright_since = u'2013'
if this_year != copyright_since:
    copyright = u'{0}-{1}, typedef int GmbH'.format(copyright_since, this_year)
else:
    copyright = u'{0}, typedef int GmbH'.format(copyright_since)

author = 'typedef int GmbH'
version = release = __version__


# -- General configuration ---------------------------------------------------

# Add the _extensions directory to Python path for custom lexers
sys.path.insert(0, os.path.abspath('_extensions'))

# Import and register the Just lexer
from just_lexer import JustLexer
from sphinx.highlighting import lexers

# Register the lexer
lexers['just'] = JustLexer()

extensions = [
    'sphinxcontrib.spelling',
    'sphinx.ext.autodoc',
    'sphinx.ext.intersphinx',

    # Usage: .. thumbnail:: picture.png
    # 'sphinxcontrib.images',
]

# https://pythonhosted.org/sphinxcontrib-images/#how-to-configure
images_config = {
    'override_image_directive': False
}

# extensions not available on RTD
if spelling is not None:
    extensions.append('sphinxcontrib.spelling')
    spelling_lang = 'en_US'
    spelling_show_suggestions = False
    spelling_word_list_filename = 'spelling_wordlist.txt'

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', '_work', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
# https://pradyunsg.me/furo/customisation/colors/#code-block-styling
pygments_style = 'sphinx'
pygments_dark_style = 'monokai'


# -- Options for HTML output -------------------------------------------------

# Use Furo theme for modern, clean documentation
html_theme = 'furo'

# Web fonts for consistent typography across browsers
# The issue is that web fonts need to be explicitly loaded. Your system has
# Noto fonts installed, but browsers can't access system fonts directly
html_css_files = [
    'https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Noto+Sans+Mono:wght@100..900&family=Noto+Serif:ital,wght@0,100..900;1,100..900&display=swap',
]

# Note: Keep old logo for backwards compatibility, but Furo will use light_logo/dark_logo
html_logo = '_static/img/crossbar.svg'

# Furo theme options
# https://pradyunsg.me/furo/customisation/
html_theme_options = {
    'sidebar_hide_name': True,
    # Note: DO NOT use _static/ prefix here (Furo requirement)
    'light_logo': 'img/typedefint-vectorized.svg',
    'dark_logo': 'img/typedefint-vectorized-white.svg',
    'light_css_variables': {
        'color-brand-primary': '#0077FF',  # Light blue
        'color-brand-content': '#0077FF',
        'color-background-primary': '#fafafa',  # Refined white
        'color-foreground-primary': '#1a1a1a',  # Anthracite
        # Noto fonts from Google Fonts
        # https://pradyunsg.me/furo/customisation/fonts/
        'font-stack': "'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
        'font-stack--headings': "'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
        'font-stack--monospace': "'Noto Sans Mono', Monaco, Consolas, monospace",
    },
    'dark_css_variables': {
        'color-background-primary': '#1A1A1A',  # Anthracite
        'color-foreground-primary': '#FAFAFA',  # Refined white
        'color-link': '#F0C359',
        'color-link--hover': '#FFBC1D',
        'color-link--visited': '#B98406',
        'color-link--visited--hover': '#EAB128',
        'color-brand-primary': '#F0C359',
        'color-brand-content': '#F0C359',
        # Noto fonts from Google Fonts
        'font-stack': "'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
        'font-stack--headings': "'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
        'font-stack--monospace': "'Noto Sans Mono', Monaco, Consolas, monospace",
    },
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_favicon = '_static/favicon.ico'

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself.  Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

intersphinx_mapping = {
    'python': ('https://docs.python.org/', None),
    'py2': ('https://docs.python.org/2', None),
    'py3': ('https://docs.python.org/3', None),

    # 404 Client Error: Not Found for url: https://pythonhosted.org/six/objects.inv
    # 'six': ('https://pythonhosted.org/six/', None),
}

rst_epilog = """
"""

rst_prolog = """
"""

# http://stackoverflow.com/questions/5599254/how-to-use-sphinxs-autodoc-to-document-a-classs-init-self-method
autoclass_content = 'both'

# http://www.sphinx-doc.org/en/stable/ext/autodoc.html#confval-autodoc_member_order
autodoc_member_order = 'bysource'
